package com.usian.behavior.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.behavior.mapper.ApBehaviorEntryMapper;
import com.usian.behavior.service.ApBehaviorEntryService;
import com.usian.model.behavior.pojos.ApBehaviorEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ApBehaviorEntryServiceImpl implements ApBehaviorEntryService {

    @Autowired
    private ApBehaviorEntryMapper apBehaviorEntryMapper;


    @Override
    public ApBehaviorEntry findByUserIdOrEquipmentId(Integer userId, Integer equipmentId) {
        //entry_id  可以= userid  可以=设备Id
        // 先根据用户Id 查询行为实体数据
        if(userId!=null){
            return apBehaviorEntryMapper.selectOne(Wrappers.<ApBehaviorEntry>lambdaQuery()
                    .eq(ApBehaviorEntry::getEntryId,userId)
                    .eq(ApBehaviorEntry::getType,1));
        }
        if(userId==null && equipmentId!=null && equipmentId !=0){
            return apBehaviorEntryMapper.selectOne(Wrappers.<ApBehaviorEntry>lambdaQuery()
                    .eq(ApBehaviorEntry::getEntryId,equipmentId)
                    .eq(ApBehaviorEntry::getType,0));
        }
        return null;
    }
}
